package mathMethod;

public class LastRemaining {

    /**
     * JZ46 孩子们的游戏
     *
     * 总结：约瑟夫问题
     * @param args
     */
    public static void main(String[] args) {

    }

    public int LastRemaining_Solution(int n, int m) {
        if (n <= 0)
            return -1;
        int index = 0;
        for (int i = 2; i <= n; i++){
            index = (index + m) % i;
        }
        return index;
    }
}
